package com.qyer.search.model.result;

import static com.qyer.search.model.lastminute.SKU.FIELD_OUT_TYPE1;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.qyer.search.model.lastminute.VSKU;
import org.apache.commons.collections4.CollectionUtils;

import java.util.*;

/**
 * Created by tangzheng on 16/7/18.
 */
public class Type1SearchEntity extends SearchEntity{

  @JsonProperty(FIELD_OUT_TYPE1)
  private int type1;

  public Type1SearchEntity() {
  }

  public Type1SearchEntity(int type1) {
    this.type1 = type1;
  }

  public Type1SearchEntity(int listSize, int type1) {
    super(listSize);
    this.type1 = type1;
  }

  public int getType1() {
    return type1;
  }

  public void setType1(int type1) {
    this.type1 = type1;
  }

  public void splitByprefer(Set<Integer> stg, int st, List<VSKU> prefer, List<VSKU> common){
    if(st <= 0){
      common.addAll(this.commonSkus);
    }else if(CollectionUtils.isEmpty(stg)){
      common.addAll(this.commonSkus);
    }else {
      if(stg.contains(this.type1)){
        for(VSKU vsku:this.commonSkus){
          if(vsku.getStype().contains(st)){
            prefer.add(vsku);
          }else {
            common.add(vsku);
          }
        }
      }else {
        common.addAll(this.commonSkus);
      }
    }
  }

  public void splitByprefer2(Set<Integer> stg, int st, List<VSKU> prefer, List<VSKU> common){
    if(CollectionUtils.isEmpty(stg)){
      common.addAll(this.commonSkus);
    }else if(st <= 0){
      if(stg.contains(this.type1)){
        prefer.addAll(this.commonSkus);
      }else {
        common.addAll(this.commonSkus);
      }
    } else {
      if(stg.contains(this.type1)){
        for(VSKU vsku:this.commonSkus){
          if(vsku.getStype().contains(st)){
            prefer.add(vsku);
          }else {
            common.add(vsku);
          }
        }
      }else {
        common.addAll(this.commonSkus);
      }
    }
  }

  public void splitBypreferAll(Set<Integer> stg, int st, List<VSKU> prefer, List<VSKU> common){
    if(CollectionUtils.isEmpty(stg)){
      common.addAll(this.skus);
    }else if(st <= 0){
      if(stg.contains(this.type1)){
        prefer.addAll(this.skus);
      }else {
        common.addAll(this.skus);
      }
    } else {
      if(stg.contains(this.type1)){
        for(VSKU vsku:this.skus){
          if(vsku.getStype().contains(st)){
            prefer.add(vsku);
          }else {
            common.add(vsku);
          }
        }
      }else {
        common.addAll(this.skus);
      }
    }
  }

  public Type1SearchEntity copy(){
    Type1SearchEntity type1SearchEntity = new Type1SearchEntity(this.packageSize, this.type1);
    type1SearchEntity.addSkus(this.skus);
    type1SearchEntity.setPackageSize(this.packageSize);
    return type1SearchEntity;
  }
}
